The "Backus-Naur Form" (BNF) is a simple yet powerful meta-language. It is a context-free grammar that defines syntax rules in terms of terminal characters (the content of the source text) and non-terminal elements (the syntax of the source language). BNF supports alternative definitions and recursion.
Extended BNF conforms to the International Standard ISO-14977. The improved language is expressive and easy to use.
BNF for Java implements Extended BNF as a working compiler and parser, providing command-line tools, as well as the complete Java API. BNF for Java implements context, and allows you to add your own powerful extensions, such as custom code generation, or database lookup during parsing.
The BNF for Java Project, hosted on SourceForge, is an open-source, community-based team project. The goal is to deliver this useful technology to the world's community of programmers.
(* Here is the phrase structure for our greeting *) hello world = greeting word, (* an introductory word with no meaning *) " ", (* a space *) any name, (* see below *) "!"; (* phrase terminator *) (* two ways to spell it: *) greeting word = 'H','e','l','l','o' (* this exact spelling *) | 'H','i'; (* | or this *) (* What's in a name? Nobody knows! So we declare our own rule: *) any name = capital letter, (* one capital, *) { small letter }; (* followed by { zero or more small letters } *) capital letter = 'A' | 'B' | 'C' | 'D' | 'E' | 'F' | 'G' | 'H' | 'I' (* any one of these terminals *) | 'J' | 'K' | 'L' | 'M' | 'N' | 'O' | 'P' | 'Q' | 'R' (* is a "capital letter" *) | 'S' | 'T' | 'U' | 'V' | 'W' | 'X' | 'Y' | 'Z'; small letter = 'a' | 'b' | 'c' | 'd' | 'e' | 'f' | 'g' | 'h' | 'i' (* any one of these terminals *) | 'j' | 'k' | 'l' | 'm' | 'n' | 'o' | 'p' | 'q' | 'r' (* is a "small letter" *) | 's' | 't' | 'u' | 'v' | 'w' | 'x' | 'y' | 'z';
source string | pass | reason |
---|---|---|
Hello World! | pass | correct syntax |
Hi Mother! | pass | really the same syntax |
Hello mom! | fail | name must start with a Capital |
Hello Mother | fail | phrase needs a "!" terminator |
Hi Mother dearest! | fail | only one name is allowed |
Writing a compiler takes twice as much effort as coding a script.
And then, writing a compiler-compiler is even more trouble!
So, why would any sane programmmer dedicate so much effort into parser technology?
Is it: (select one)
Our "digits.com" web counter: